package com.cn.kabalifemerchants.ui.user.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.cn.kabalifemerchants.R;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.base.IBaseActivity;
import com.cn.kabalifemerchants.base.MyApplication;
import com.cn.kabalifemerchants.ui.user.bean.AppVersionBean;
import com.cn.kabalifemerchants.utils.RxToast;
import com.flyco.roundview.RoundTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 晓林 on 2020/10/20.
 * function:
 */
public class EditionActivity extends IBaseActivity {
    @BindView(R.id.tv_edition)
    TextView tvEdition;
    @BindView(R.id.tv_msg)
    RoundTextView tvMsg;

    AppVersionBean appVersionBean;
    Bundle bundle;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.recruit_edition;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);

        setTitleBar("版本更新");
        bundle = getIntent().getExtras();
        appVersionBean = (AppVersionBean) bundle.getSerializable("appVersionBean");
        tvEdition.setText("v " + MyApplication.getVersionName());
        if (MyApplication.getVersionName().equals(appVersionBean.getResult().getVersion())) {
            tvMsg.setVisibility(View.GONE);
        } else tvMsg.setVisibility(View.VISIBLE);
    }

    @OnClick({R.id.ll_btn_help, R.id.ll_btn_edition})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_btn_help:
                Bundle bundle = new Bundle();
                bundle.putString("title", "功能介绍");
                bundle.putString("content", appVersionBean.getResult().getContent());
                $startActivity(RichTextH5Activity.class, bundle);
                break;
            case R.id.ll_btn_edition:
                if (appVersionBean != null) {
                    if (MyApplication.getVersionName().equals(appVersionBean.getResult().getVersion())) {
                        RxToast.success("当前已是最新版本");
                    } else {
                        Intent intent = new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        Uri content_url = Uri.parse(appVersionBean.getResult().getUrl());
                        intent.setData(content_url);
                        startActivity(intent);
                    }
                }
                break;
        }
    }
}
